<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class AddToPermissionsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        if (Schema::hasTable('permissions')) {
            Schema::table('permissions', function (Blueprint $table) {
                $table->bigInteger('parent_id')->nullable()->after('id')->comment('上级ID');
                $table->string('title')->after('guard_name')->comment('权限标题');
                $table->boolean('index')->default(false)->after('title')->comment('同一组接口权限中是否为基础接口权限 true:同一组接口权限中的其他权限依赖于此接口权限');
                $table->boolean('menu')->default(false)->after('index')->comment('是否为菜单');
                $table->string('page_name')->nullable()->after('menu')->comment('当设置为菜单时 需要设置前端页面名称');
                $table->boolean('hidden_menu')->default(false)->after('page_name')->comment('是否隐藏菜单');
                $table->integer('sort')->default(0)->after('hidden_menu')->comment('菜单排序 数值越小越靠前');
                $table->string('icon', 100)->nullable()->after('sort')->comment('菜单图标');
                $table->string('description')->nullable()->comment('描述');
                $table->unsignedInteger('_lft')->nullable()->after('icon');
                $table->unsignedInteger('_rgt')->nullable()->after('_lft');

                // 索引
                $table->index('parent_id', 'parent_id_index');
                // $table->index('name', 'name_index');
                $table->index('menu', 'menu_index');
                // $table->index(['id', 'guard_name'], 'id_guard_name_index');
                $table->index(['name', 'guard_name'], 'name_guard_name_index');
                // $table->index(['_lft', '_rgt'], '_lft_rgt_index');
            });
        }
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('permissions', function (Blueprint $table) {
            //
        });
    }
}
